package com.jiazhong.mybatis.m2.mapper;

import com.jiazhong.commons.bean.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmpMapper {
    @Select("select * from emp where state=1")
    List<Emp> findAll();

    @Select("select * from emp where state=1 and empno=#{id}")
    Emp findById(int id);

    @Select("select * from emp where state=1 and ename like #{name}")
    List<Emp> findByName(String name);

    @Select("select * from emp where state=1 and ename like #{ename} and job=#{job}")
    List<Emp> findByEnameAndJob(@Param("ename") String ename, @Param("job") String job);

    @Insert("insert into emp values(null,#{ename},#{job},#{mgr},now(),#{sal},#{comm},#{deptNo},1)")
    int insert(Emp emp);
    @Update("update emp set ename=#{ename},job=#{job},mgr=#{mgr},sal=#{sal} where empno=#{empNo}")
    int update(Emp emp);
    @Update("update emp set state=0 where empno=#{id}")
    int delete(int id);
}
